package net.crowdloud.client.tags;

import java.util.List;

import net.crowdloud.shared.entities.Tags;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;

/**
 * 
 * @Feature
 */
public class TagsList extends FlexTable {

	public TagsList(List<Tags> tags) {

		setBorderWidth(1);
		setWidth("900px");

		setCellPadding(5);

		gridColumns();

		gridRows(tags);
	}

	private void gridColumns() {

		this.setHTML(0, 0, "<B>TAG</B>");
		this.getColumnFormatter().setWidth(0, "200px");

		this.setHTML(0, 1, "<B>Customers</B>");
		this.getColumnFormatter().setWidth(1, "250px");

		this.setHTML(0, 2, "<B>Providers</B>");
		this.getColumnFormatter().setWidth(2, "250px");

		this.setHTML(0, 3, "<B>Status</B>");
		this.getColumnFormatter().setWidth(5, "50px");

		this.setHTML(0, 4, " ");
		this.getColumnFormatter().setWidth(6, "50px");
	}

	private void gridRows(List<Tags> tags) {

		if (tags != null) {

			int row = 0;
			for (Tags tag : tags) {

				row++;

				this.setText(row, 0, tag.getTagName());
				this.setText(row, 1, tag.getUserCustomers().size() + "");
				this.setText(row, 2, tag.getUserProviders().size() + "");

				/*
				 * String priority = ""; if (backlogEntry.getBacklogPriority()
				 * != null) { priority =
				 * backlogEntry.getBacklogPriority().toString(); }
				 */
				this.setText(row, 3, "");

				HorizontalPanel hp = new HorizontalPanel();
				hp.setSpacing(10);

				this.setWidget(row, 4, hp);

			}
		}
	}

}
